package com.ipartek.formacion.miprimerwebapp.sevlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class GETPOSTServlet
 */
public class GETPOSTServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    
	private static final String view_GETPOSTServlet = "ejemploGETPOST.jsp";
    private RequestDispatcher dispatcher = null;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public GETPOSTServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//obtener el dispatcher
		dispatcher = request.getRequestDispatcher(view_GETPOSTServlet);
		
		//recogiendo el metodo
		request.setAttribute("metodo", "GET");
		
		//recogiendo datos del formulario
				
		
		//hacemos el forward
		dispatcher.forward(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		//obtener el dispatcher
		dispatcher = request.getRequestDispatcher(view_GETPOSTServlet);
		
		//recogiendo el metodo
		request.setAttribute("metodo", "POST");
		
		System.out.println(request.getParameter("nombre"));
		System.out.println(request.getParameter("apellidos"));
		System.out.println(request.getParameter("edad"));
		System.out.println(request.getParameter("lenguaje"));
		System.out.println(request.getParameter("preferencia"));
		
		
		//hacemos el forward
		dispatcher.forward(request, response);
	}
}